package org.example.binaryoperator;

import com.alibaba.fastjson.JSONObject;

import java.util.List;
import java.util.function.BinaryOperator;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Java8BinaryOperator2 {
    public static void main(String[] args) {
        List<Integer> numbers = IntStream.range(1,11).boxed().collect(Collectors.toList());
        System.err.println(JSONObject.toJSONString(numbers));
        Integer result = math(numbers,0, Integer::sum);
        System.err.println(result);

    }

    static <T> T math(List<T> list, T init, BinaryOperator<T> bo){
        T result = init;
        for (T t : list) {
            result = bo.apply(result,t);
        }
        return result;
    }
}
